{extend name='common/common' /}

{block name="style"}
<style>
    .ibox-content{
        padding: 0px;
        border-top: none;
    }
    .layui-elem-field legend {
        margin-left: 0px;
        font-size: 20px;
        font-weight: 300;
        padding: 0px 10px;
        margin-bottom: 0px;
    }
    .form-group{
        line-height: 34px;
    }
    textarea.form-control{
        height: 100px;
    }
    .checkbox label, .radio label{
        line-height: 5px;
    }
    .configure{
        border: 1px solid #e5e6e7;
        min-height: 40px;
    }
    .fa.fa-remove{
        display: none;
    }
    .badge{
        display: none;
    }
	.m-t{
		padding-top:15px;
		margin-top: 0px;
	}
	.form-horizontal .control-label{
		padding-top: 0px;
	}
	tbody tr{
		cursor: pointer;
	}
</style>
{/block}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-10">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
					<div class="layui-tab layui-tab-card" lay-filter="test">
                        <ul class="layui-tab-title">
                            <li class="layui-this" lay-id="77">已有客户录入</li>
                            <li lay-id="88">新增客户录入</li>
                        </ul>
                        <div class="layui-tab-content" style="height: auto;">
							<!--  已有客户录入  -->
							<div class="layui-tab-item layui-show">
								<form class="form-horizontal m-t" id="orderAdd_1" method="post" action="{:url('Order/orderAdd')}">
									<!-- 录入信息 -->
									<input type="hidden" id="relation_id" name="relation_id" value=""/>
									<input type="hidden" id="time" name="time" value=""/>

									<div class="form-group">
			                            <label class="col-sm-3 control-label">姓名：</label>
			                            <div class="input-group col-sm-7">
											<input id="m_id" type="hidden" class="form-control" name="m_id" required="" aria-required="true" >
			                                <input id="m_mame" type="text" class="form-control" name="stu_name" required="" aria-required="true"
											readonly placeholder="点击选择客户">
			                            </div>
			                        </div>

			                        <div class="form-group mem_mobile">
			                            <label class="col-sm-3 control-label">联系电话：</label>
			                            <div class="input-group col-sm-7">
			                                <input id="phone" type="text" class="form-control" name="phone" required="" aria-required="true"
											readonly>
			                            </div>
			                        </div>

									<div class="form-group">
                                        <label class="col-sm-3 control-label">地		址：</label>
                                        <div class="input-group col-sm-7">
                                            <input id="adress" type="text" class="form-control" name="adress" required="" aria-required="true" value="">
                                        </div>
                                    </div>

									<div class="form-group">
                                        <label class="col-sm-3 control-label">民　　族：</label>
                                        <div class="input-group col-sm-7">
                                            <input id="nation" type="text" class="form-control" name="nation" required="" aria-required="true" value="">
                                        </div>
                                    </div>
									<div class="form-group">
										<label class="col-sm-3 control-label">身份证号：</label>
										<div class="input-group col-sm-7">
											<input id="id_card" type="text" class="form-control" name="id_card" required="" aria-required="true" value="">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-3 control-label">生　　日：</label>
										<div class="input-group col-sm-7">
											<input id="birthday" type="text" class="form-control" name="birthday" required="" aria-required="true" value="">
										</div>
									</div>
									<div class="form-group">
                                        <label class="col-sm-3 control-label">性　　别:</label>
                                        <div class="input-group col-sm-7">
                                            <select name="sex" id="sex" class="form-control" >
                                                <option value="1">男</option>
												<option value="2">女</option>
                                            </select>
                                        </div>
                                    </div>

			                        <div class="form-group">
			                            <label class="col-sm-3 control-label">报考院校：</label>
			                            <div class="input-group col-sm-7">
			                                <input type="hidden" class="form-control school_id" name="school_id"
			                                       required="" aria-required="true">
			                                <input type="text" class="form-control school" name="school" required=""
			                                       aria-required="true" readonly placeholder="点击选择学校和专业">
			                            </div>
			                        </div>
			                        <div class="form-group">
			                            <label class="col-sm-3 control-label">就读专业：</label>
			                            <div class="input-group col-sm-7">
			                                <input type="hidden" class="form-control major_id" name="major_id"
			                                       required="" aria-required="true">
			                                <input type="text" class="form-control major" name="major"
			                                       required="" aria-required="true" readonly placeholder="点击选择学校和专业">
			                            </div>
			                        </div>
			                        <div class="form-group">
			                            <label class="col-sm-3 control-label">产品名称：</label>
			                            <div class="input-group col-sm-7">
			                                <select name="name" class="form-control product_name" >
			                                    <option value="">请选择</option>
			                                </select>
			                            </div>
			                        </div>

			                        <div class="form-group">
			                            <label class="col-sm-3 control-label">配置:</label>
			                            <div class="input-group col-sm-7 configure">

			                            </div>
			                        </div>

			                        <div class="form-group">
			                            <label class="col-sm-3 control-label">支付方式：</label>
			                            <div class="input-group col-sm-7">
			                                <select name="pay_type" id="pay_type" class="form-control">
			                                    <option value="">请选择</option>
												<?php foreach($payTypeArr as $val):?>
			                                    	<option value="<?=$val['id']?>"><?=$val['name']?></option>
												<?php endforeach;?>
			                                </select>
			                            </div>
			                        </div>
			                        <div class="form-group">
			                            <label class="col-sm-3 control-label">备注：</label>
			                            <div class="input-group col-sm-7">
			                                <input id="ord_remarks" class="form-control" name="remarks">
			                            </div>
			                        </div>
			                        <div class="form-group">
			                            <div class="col-sm-5 col-sm-offset-7" style="padding-left: 6%">
			                                <button class="btn btn-primary" type="submit" style="margin-right: 25px">确认提交</button>
			                                <a href="javascript:;" onclick="javascript:history.back(-1);">
			                                    <button type="button" class="btn btn-primary btn-sm" style="width: 82px;height: 34px;">
			                                        返回
			                                    </button>
			                                </a>
			                            </div>
			                        </div>
			                    </form>
							</div>
							<!-- 新增客户录入 -->
							<div class="layui-tab-item">
								<form class="form-horizontal m-t" id="orderAdd_2" method="post" action="{:url('Order/orderAdd')}">

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">姓名：</label>
                                        <div class="input-group col-sm-7">
                                            <!-- 报考者名字 -->
                                            <input id="stu_name" type="text" class="form-control" name="stu_name" required="" aria-required="true" value="">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">联系电话：</label>
                                        <div class="input-group col-sm-7">
                                            <input id="ord_phone" type="text" class="form-control" name="phone" required="" aria-required="true" value="">
                                        </div>
                                    </div>

									<div class="form-group">
										<label class="col-sm-3 control-label">QQ：</label>
										<div class="input-group col-sm-7">
											<input id="qq" class="form-control" name="qq" value="">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-3 control-label">微信：</label>
										<div class="input-group col-sm-7">
											<input id="weixin" class="form-control" name="weixin" value="">
										</div>
									</div>

									<div class="form-group">
                                        <label class="col-sm-3 control-label">地		址：</label>
                                        <div class="input-group col-sm-7">
                                            <input id="adress" type="text" class="form-control" name="adress" required="" aria-required="true" value="">
                                        </div>
                                    </div>

									<div class="form-group">
                                        <label class="col-sm-3 control-label">民　　族：</label>
                                        <div class="input-group col-sm-7">
                                            <input id="nation" type="text" class="form-control" name="nation" required="" aria-required="true" value="">
                                        </div>
                                    </div>
									<div class="form-group">
										<label class="col-sm-3 control-label">身份证号：</label>
										<div class="input-group col-sm-7">
											<input id="id_card" type="text" class="form-control" name="id_card" required="" aria-required="true" value="">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-3 control-label">生　　日：</label>
										<div class="input-group col-sm-7">
											<input id="birthdayK" type="text" class="form-control" name="birthday" required="" aria-required="true" value="">
										</div>
									</div>
									<div class="form-group">
                                        <label class="col-sm-3 control-label">性　　别:</label>
                                        <div class="input-group col-sm-7">
                                            <select name="sex" id="sex" class="form-control" >
                                                <option value="1">男</option>
												<option value="2">女</option>
                                            </select>
                                        </div>
                                    </div>


                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">报考院校：</label>
                                        <div class="input-group col-sm-7">
                                            <input type="hidden" class="form-control school_id" name="school_id"
                                                   required="" aria-required="true">
                                            <input type="text" class="form-control school" name="school" required=""
                                                   aria-required="true" readonly placeholder="点击选择学校和专业">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">就读专业：</label>
                                        <div class="input-group col-sm-7">
                                            <input type="hidden" class="form-control major_id" name="major_id"
                                                   required="" aria-required="true">
                                            <input type="text" class="form-control major" name="major"
                                                   required="" aria-required="true" readonly placeholder="点击选择学校和专业">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">产品名称：</label>
                                        <div class="input-group col-sm-7">
                                            <select name="name" class="form-control product_name" >
                                                <option value="">请选择</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">配置:</label>
                                        <div class="input-group col-sm-7 configure">

                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">支付方式：</label>
                                        <div class="input-group col-sm-7">
                                            <select name="pay_type" id="pay_type" class="form-control">
                                                <option value="">请选择</option>
                                                <?php foreach($payTypeArr as $val): ?>
                                                    <option value="<?=$val['id'];?>"><?=$val['name'];?></option>
                                                <?php endforeach;?>
                                            </select>
                                        </div>
                                    </div>
									<!-- 所属咨询师 -->
									<div class="form-group">
                                        <label class="col-sm-3 control-label">所属咨询师：</label>
                                        <div class="input-group col-sm-7">
											<input type="hidden" id="King_id" class="form-control" name="relation_id">
                                            <input id="relation" class="form-control" name="relation" readonly placeholder="请点击选择所属咨询师">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">备注：</label>
                                        <div class="input-group col-sm-7">
                                            <input id="ord_remarks" class="form-control" name="remarks">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-5 col-sm-offset-7" style="padding-left: 6%">
                                            <button class="btn btn-primary" type="submit" style="margin-right: 25px">确认提交</button>
                                            <a href="javascript:;" onclick="javascript:history.back(-1);">
                                                <button type="button" class="btn btn-primary btn-sm" style="width: 82px;height: 34px;">
                                                    返回
                                                </button>
                                            </a>
                                        </div>
                                    </div>
                                </form>
							</div>
						</div>
					</div>
				</div>
            </div>
        </div>
    </div>
</div>

<div class="laycontent" style="display: none;width: 300px;padding: 30px 15px;">
    <ul id="tree"></ul>
</div>

<!-- 选择所属咨询师 -->
<div class="department" style="display: none;">
	<div class="wrapper wrapper-content animated fadeInRight">
	    <!-- Panel Other -->
	    <div class="ibox float-e-margins">
	        <div class="ibox-title">
	            <h5>职员列表</h5>
	        </div>
	        <div class="ibox-content">
	            <!--搜索框开始-->
	            <form id='commentForm' role="form" method="post" class="form-inline pull-right">
	                <div class="content clearfix m-b">
	                    <div class="form-group">
	                        <label>职员名称：</label>
	                        <input type="text" class="form-control" id="username" name="user_name">
	                    </div>
	                    <div class="form-group">
	                        <button class="btn btn-primary" type="button" style="margin-top:5px" id="search"><strong>搜 索</strong>
	                        </button>
	                    </div>
	                </div>
	            </form>
	            <!--搜索框结束-->
	            <div class="example-wrap">
	                <div class="example">
	                    <table id="cusTable">
	                        <thead>
	                        <th data-field="id">职员ID</th>
	                        <th data-field="user_name">职员名称</th>
	                        <th data-field="role_name">职员角色</th>
	                        <!-- <th data-field="login_times">登录次数</th> -->
	                        <!-- <th data-field="last_login_ip">上次登录ip</th> -->
	                        <!-- <th data-field="last_login_time">上次登录时间</th> -->
	                        <th data-field="real_name">真实姓名</th>
	                        <th data-field="status">状态</th>
	                        <!-- <th data-field="operate">操作</th> -->
	                        </thead>
	                    </table>
	                </div>
	            </div>
	            <!-- End Example Pagination -->
	        </div>
	    </div>
	</div>
</div>
{/block}

{block name="script"}
<script type="text/javascript">
    function initTable() {
        //先销毁表格
        $('#cusTable').bootstrapTable('destroy');
        //初始化表格,动态从服务器加载数据
        $("#cusTable").bootstrapTable({
            method: "get",  //使用get请求到服务器获取数据
            url: "{:url('User/index')}", //获取数据的地址
            striped: true,  //表格显示条纹
            pagination: true, //启动分页
            pageSize: 10,  //每页显示的记录数
            pageNumber:1, //当前第几页
            pageList: [5, 10, 15, 20, 25],  //记录数可选列表
            sidePagination: "server", //表示服务端请求
            paginationFirstText: "首页",
            paginationPreText: "上一页",
            paginationNextText: "下一页",
            paginationLastText: "尾页",
            queryParamsType : "undefined",
			onDblClickRow: function (row) {
				$('#relation').val(row.real_name);
				$('#King_id').val(row.id);
				layer.closeAll();
	        },
            queryParams: function queryParams(params) {   //设置查询参数
                var param = {
                    pageNumber: params.pageNumber,
                    pageSize: params.pageSize,
                    searchText:$('#username').val()
                };
                return param;
            },
            onLoadSuccess: function(res){  //加载成功时执行
                if(111 == res.code){
                    window.location.reload();
                }
                layer.msg("加载成功", {time : 1000});
            },
            onLoadError: function(){  //加载失败时执行
                layer.msg("加载数据失败");
            }
        });
    }

    $(document).ready(function () {
        //调用函数，初始化表格
        initTable();

        //当点击查询按钮的时候执行
        $("#search").bind("click", initTable);
    });
</script>
<!-- <script src="__JS__/jquery.min.js?v=2.1.4"></script> -->
<script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
<script src="__JS__/content.min.js?v=1.0.0"></script>
<script src="__JS__/plugins/bootstrap-tagsinput/bootstrap-tagsinput.min.js"></script>
<script src="__JS__/plugins/validate/jquery.validate.min.js"></script>
<script src="__JS__/plugins/validate/messages_zh.min.js"></script>
<script src="__JS__/layui/layui.js"></script>
<script src="__JS__/jquery.form.js"></script>
<script type="text/javascript">
    var index = '';
    function showStart(){
        index = layer.load(0, {shade: false});
        return true;
    }
    function showSuccess(res){

        layer.ready(function(){
            layer.close(index);
            if(1 == res.code){
                layer.alert(res.msg, {title: '友情提示', icon: 1, closeBtn: 0}, function(){
                    window.location.href = "{:url('finance/orderInput')}";
                });
            }else if(111 == res.code){
                window.location.reload();
            }else{
                layer.msg(res.msg, {anim: 6});
            }
        });
    }
    $(document).ready(function(){
        // 添加角色
        var options = {
            beforeSubmit:showStart,
            success:showSuccess
        };
        // 已有客户录入
        $('#orderAdd_1').submit(function(){
            config();
            $(this).ajaxSubmit(options);
            return false;
        });
		// 新增客户录入
        $('#orderAdd_2').submit(function(){
            config();
            $(this).ajaxSubmit(options);
            return false;
        });
    });
    // 表单验证
    $.validator.setDefaults({
        highlight: function(e) {
            $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
        },
        success: function(e) {
            e.closest(".form-group").removeClass("has-error").addClass("has-success")
        },
        errorElement: "span",
        errorPlacement: function(e, r) {
            e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
        },
        errorClass: "help-block m-b-none",
        validClass: "help-block m-b-none"
    });
</script>

<script>
    $(function(){
        getTree();
        layui.use(['form'], function(){
            var form = layui.form;
        });

		//点击添加客户信息
		$('#m_mame').on('click',function(){
			selectSchoolBox = layer.open({
                type: 2,
                title: '请选择成交客户',
                anim: 2,
                skin: 'layui-layer-molv', //加上边框
                area: ['80%', '80%'], //宽高
                content: "{:url('memList')}"
            });
		})

        $('.school').on('click',function(){
            selectSchoolBox = layer.open({
                type: 1,
                title: '请选择学校和专业',
                anim: 2,
                skin: 'layui-layer-molv', //加上边框
                area: ['300px', '450px'], //宽高
                content: $(".laycontent")
            });
        });
        $('.major').on('click',function(){
            selectSchoolBox = layer.open({
                type: 1,
                title: '请选择学校和专业',
                anim: 2,
                skin: 'layui-layer-molv', //加上边框
                area: ['300px', '350px'], //宽高
                content: $(".laycontent")
            });
        });
    })
    function getTree(){
        layui.use(['tree', 'layer'], function(){
            var layer = layui.layer;

            $.getJSON("{:url('product/school')}", function(res){
                if(111 == res.code){
                    window.location.reload();
                }
                layui.tree({
                    elem: '#tree'
                    ,nodes: res.data
                    ,click: function(node){
                        if(node.pid != 0){
                            $('.major').val(node.name);
                            $('.major_id').val(node.id);
                            for(var i=0;i<res.data.length;i++){
                                if(node.pid == res.data[i].id){
                                    $('.school').val(res.data[i].name);
                                    $('.school_id').val(res.data[i].id);
                                }
                            }
                            layer.closeAll();
                        }
                        var school_id = node.pid;
                        var major_id = node.id;
                        $.post("{:url('order/productList')}",{
                            school_id:school_id,
                            major_id:major_id
                        },function (data) {
                            if (data != null || data != '') {
                                var app = '<option value="">请选择</option>';
                                for(var i in data){
                                    app += '<option value="'+data[i]["id"]+'">'+data[i]["name"]+'</option>'
                                }
                                $('.product_name').html(app);
                                $('.product_name').on('change',function(){
                                    var product_id = $(this).val();
                                    $.post("{:url('Order/configList')}",{
                                        product_id:product_id
                                    },function (res) {
                                        var king = '';
                                        for(var i=0;i<res.data.length;i++){
                                            king += '<p><input type="radio" name="cofigArr" id="cofigArr">' + res.data[i] + '</p>';
                                        }
                                        $('.configure').html(king);

                                        var aBadge = $('.badge');
                                        for(var i=0;i<aBadge.length;i++){
                                            console.log(aBadge[i].getAttribute('data-param'));
                                        }
                                    })
                                })
                            } else{
                                layer.msg('没有产品', {time : 1000});
                            }
                        })
                    }
                });
            });
        });
    }
    //重写配置
    function config() {
        $('input[name="cofigArr"]').each(function(){
            if($(this).is(':checked')){
                var val;
                val = $(this).siblings('.badge').attr('data-param');
                $(this).val(val);
            }
        })
    }
	//时间选择
    layui.use('laydate', function() {
        var laydate = layui.laydate;
		laydate.render({
			elem: '#birthday',
			type: 'date'
		});
		var laydate = layui.laydate;
		laydate.render({
			elem: '#birthdayK',
			type: 'date'
		});
    })
	layui.use('element', function(){
        var $ = layui.jquery ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块

        $('.site-demo-active').on('click', function(){
            var othis = $(this), type = othis.data('type');
            active[type] ? active[type].call(this, othis) : '';
        });

        //Hash地址的定位
        var layid = location.hash.replace(/^#test=/, '');
        element.tabChange('test', layid);

        element.on('tab(test)', function(elem){
            location.hash = 'test='+ $(this).attr('lay-id');
//            window.location.reload();
        });
    });
</script>
<script>
    $(function(){
        layui.use(['form'], function(){
            var form = layui.form;
        });
        $('#relation').on('click',function(){
            selectSchoolBox = layer.open({
                type: 1,
                title: '请选择所属咨询师',
                anim: 2,
				skin: 'layui-layer-molv', //加上边框
                area: ['80%', '80%'], //宽高
                // shade:false,
                skin: 'layui-layer-molv', //加上边框
                content: $(".department"),
            });
        });
    });
</script>
{/block}
